/*
    This file is part of MP3DecodeDLL for Symbian.

    MP3DecodeDLL for Symbian
    Copyright (C) 2004 Denis Mingulov <denis@mingulov.com>

    MP3DecodeDLL for Symbian is free software; you can redistribute
    it and/or modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2 of
    the License, or (at your option) any later version.

    MP3DecodeDLL for Symbian is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied
    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MP3DecodeDLL for Symbian; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#include "MP3Decode.h"
#include "MP3DecodeEngine.h"
#include "MP3DecodeNotifier.h"
#include "f32file.h"

CMP3DecodeEngine* CMP3DecodeEngine::NewL()
{
	CMP3DecodeEngine* self=NewLC();
	CleanupStack::Pop();
	return self;
}

CMP3DecodeEngine* CMP3DecodeEngine::NewLC()
{
	CMP3DecodeEngine* self=new (ELeave) CMP3DecodeEngine();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

void CMP3DecodeEngine::ConstructL()
{
	iMP3Decode = CMP3Decode::NewL();
}

CMP3DecodeEngine::CMP3DecodeEngine() : iFileSession(NULL), iState(EDoNothing), bFileOpened(EFalse), iMP3Decode(NULL)
{
}

CMP3DecodeEngine::~CMP3DecodeEngine()
{
	delete iMP3Decode;
}

void CMP3DecodeEngine::ChangeState (TMP3DecodeEngineState aState)
{
	iState = aState;
}

TMP3DecodeEngineState CMP3DecodeEngine::GetState()
{
	return iState;
}

TInt CMP3DecodeEngine::SetEqualizer(TInt aEq60, TInt aEq170, TInt aEq310, TInt aEq600, TInt aEq1K, TInt aEq3K, TInt aEq6K, TInt aEq12K, TInt aEq14K, TInt aEq16K, TInt aEqZero, TInt aEqDiv)
{
	iMP3Decode->SetEqualizer(aEq60, aEq170, aEq310, aEq600, aEq1K, aEq3K, aEq6K, aEq12K, aEq14K, aEq16K, aEqZero, aEqDiv);

	return 0;
}

TInt CMP3DecodeEngine::SetResampleRate(TInt aResampleRate)
{
	return iMP3Decode->SetResampleRate(aResampleRate);
}

TInt CMP3DecodeEngine::OpenFile(RFs& aFileServer, const TDesC &aFileName, int mediaoffset, int mediarealsize)
{
	iFileSession = &aFileServer;
	strFileName.Copy(aFileName);

	TInt iErr = iMP3Decode->Open(aFileServer, aFileName, mediaoffset, mediarealsize);

	if(iErr)
	{
		ChangeState(EDoNothing);
	}
	else
		ChangeState(EOpenComplete);

	return iErr;
}

TInt CMP3DecodeEngine::CloseFile()
{
	return 0;
}

TInt CMP3DecodeEngine::DecodeStart()
{
	ChangeState(EDecoding);
	return 0;
}

TInt CMP3DecodeEngine::DecodeStop()
{
	return 0;
}

TInt CMP3DecodeEngine::DecodeOneFrame(TDes &aBuffer)
{
	TInt iR=iMP3Decode->DecodeOneFrame(aBuffer);
	return iR;
}

TInt CMP3DecodeEngine::GetFileLength()
{
	return iMP3Decode->GetFileLength();
}

TInt CMP3DecodeEngine::GetFilePosition()
{
	return iMP3Decode->GetFilePosition();
}

